package util

import (
	"encoding/json"
	"io"
	"net/http"
	"ubt-rbac-service/internal/app/model"
	"ubt-rbac-service/internal/core/logger"
)

func ToJson(w http.ResponseWriter, ret *model.ResJson) {
	if jo, err := json.Marshal(ret); err == nil {
		if _, err = io.WriteString(w, string(jo)); err != nil {
			logger.Error("返回结果输出失败！")
		}
	} else {
		logger.Error("返回结果转JSON失败！")
	}
}

func ToJson4We(w http.ResponseWriter, res *model.RetJson) {
	if jo, err := json.Marshal(res); err == nil {
		if _, err = io.WriteString(w, string(jo)); err != nil {
			logger.Error("返回结果输出失败！")
		}
	} else {
		logger.Error("返回结果转JSON失败！")
	}
}
